import { ChangeAccount, IChangeAvatar, LoginInfo, RegisterInfo, ResetPasswordInfo } from '../interface/account';
import * as request from './request'


export async function checkAccount(body: LoginInfo) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/login')
    return data
  } catch (e) {
    return (e)
  }
}

export async function registerAccount(body: RegisterInfo) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/register')
    return data
  } catch (e) {
    return (e)
  }
}

export async function focusAuthor(body: { userId: string, targetId: string }) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/focus')
    return data
  } catch (e) {
    return (e)
  }
}

export async function getUserInfo(body: { account: string }, token: string) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/getUserInfo', token)
    return data
  } catch (e) {
    return (e)
  }
}

export async function getUser(body: { userId: string }) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/getUser')
    return data
  } catch (e) {
    return (e)
  }
}

export async function getFocuseInfo(body: { focus: string[] }) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/getFocusUser')
    return data
  } catch (e) {
    return (e)
  }
}

export async function resetPasswordHandle(body: ResetPasswordInfo) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/resetPassword')
    return data
  } catch (e) {
    return (e)
  }
}

export async function changeAvatarHandle(body: IChangeAvatar) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/changeAvatar')
    return data
  } catch (e) {
    return (e)
  }
}

export async function logOutHandle(token: string) {
  try {
    const data = await request.post('', '/api/web/account/logout', token)
    return data
  } catch (e) {
    return (e)
  }
}

export async function changeAccount(body: ChangeAccount) {
  try {
    const data = await request.post(JSON.stringify(body), '/api/web/account/change')
    return data
  } catch (e) {
    return (e)
  }
}